<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>外卖设置</title>
    <script src="js/vue221.js" th:src="@{/js/vue.js}"></script>
    <script src="js/vue-router231.js" th:src="@{/js/vue-router.js}"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="css/element.css" th:href="@{/css/element.css}">
    <link rel="stylesheet" href="css/global.css" th:href="@{/css/global.css}"/>
    <link rel="stylesheet" href="css/main.css" th:href="@{/css/main.css}"/>
    <link rel="stylesheet" href="css/myelement.css" th:href="@{/css/myelement.css}"/>
    <!-- 引入组件库 -->
    <script src="js/element.js" th:src="@{/js/element.js}"></script>
</head>
<body>
<div id="app">
    <div class="main-content">
        <!-- 页面头部 -->
        <div class="page-header">
            <h1 class="page-title">外卖设置</h1>
            <div class="breadcrumb"><a href="javascript: top.location.reload();">首页</a><span>/</span>设置</div>
        </div><!-- 页面头部 end -->

        <div class="main-content-body">
            <div class="view-order mb_20">
                <div class="view-item">
                    设置外卖
                </div>
            </div>
            <div class="edit-form">
                <el-form :model="vendorBasic" :rules="rules" ref="dataForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="开启外卖" prop="supportOut">
                        <el-switch v-model="vendorBasic.supportOut"></el-switch>
                    </el-form-item>
                    <template v-if="vendorBasic.supportOut">
                    <el-form-item label="配送范围" prop="supportScope">
                        <el-input v-model.number="vendorBasic.supportScope" style="width: 80px" placeholder="店铺周边多少公里内"></el-input>公里
                    </el-form-item>
                    <el-form-item label="配送费用" prop="distributionPrice">
                        <el-input v-model.number="vendorBasic.distributionPrice" style="width: 80px" placeholder="元"></el-input>元
                    </el-form-item>
                    <el-form-item label="起送金额" prop="leastPrice">
                        <el-input v-model.number="vendorBasic.leastPrice" style="width: 80px" placeholder="元"></el-input>元
                    </el-form-item>
                    <el-form-item label="免运费额" prop="reachPrice">
                        <el-input v-model.number="vendorBasic.reachPrice" style="width: 80px" placeholder="元"></el-input>元
                    </el-form-item>
                    <el-form-item label="配送时段" prop="psTime">
                        <el-time-select v-model="vendorBasic.beginTime"
                                        :picker-options="{
                                            start: '00:00',
                                            step: '00:01',
                                            end: '23:59'
                                        }"
                                placeholder="选择时间" style="width: 110px">
                        </el-time-select>
                        - <el-time-select v-model="vendorBasic.endTime"
                                          :picker-options="{
                                            start: '00:00',
                                            step: '00:01',
                                            end: '23:59'
                                        }"
                                          placeholder="选择时间" style="width: 110px">
                          </el-time-select>
                    </el-form-item>
                    </template>

                    <div class="edit-button-fixed">
                        <div class="edit-button z-yuan-butn">
                            <el-button type="primary" @click="submitForm('dataForm')">确定</el-button>
                            <el-button @click="handelCancel()">取消</el-button>
                        </div>
                    </div>
                </el-form>

            </div>
        </div>
    </div>
</div>



</body>
<script src="js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script th:inline="javascript">
    new Vue({
        el: "#app",
        data: {
            // form 表单数据
            vendorBasic: [[${vendorBasic}]],
            // form 表单验证规则
            rules: {
                supportScope: [
                    { required: true, message: '请输入配送范围', trigger: 'blur' },
                    { type: 'number', message: '配送范围必须为数字值'}
                ],
                distributionPrice: [
                    { required: true, message: '请输入配送费用', trigger: 'blur' },
                    { type: 'number', message: '配送费用必须为数字值'}
                ],
                leastPrice: [
                    { required: true, message: '请输入起送金额', trigger: 'blur' },
                    { type: 'number', message: '起送金额必须为数字值'}
                ],
                reachPrice: [
                    { required: true, message: '请输入免运费额', trigger: 'blur' },
                    { type: 'number', message: '免运费额必须为数字值'}
                ]
            }
        },
        computed: {

        },
        methods: {
            // 提交表单
            submitForm(formName) {
                let self = this;
                self.$refs[formName].validate((valid) => {
                    if (valid) {
                        self.loading = true;
                        $.ajax({
                            url: "/vendor/vendorbasic/setOut",
                            type: "POST",
                            data: JSON.stringify(self.vendorBasic),
                            contentType: "application/json;charset=UTF-8",
                            dataType: "json",
                            success: function (data) {
                                if (data && data.returnCode == "1") {
                                    self.$message({
                                        showClose: true,
                                        duration: 1500,
                                        message: '设置外卖成功',
                                        type: 'success',
                                        customClass: 'message-center'
                                    });
                                } else {
                                    self.$message({
                                        showClose: true,
                                        duration: 1500,
                                        message: '设置外卖失败',
                                        type: 'error',
                                        customClass: 'message-center'
                                    });
                                    self.loading = false;
                                }
                            },
                            error: function () {
                                self.$message({
                                    showClose: true,
                                    duration: 1500,
                                    message: '系统异常，请联系管理员.',
                                    type: 'error',
                                    customClass: 'message-center'
                                });
                                self.loading = false;
                            }
                        });
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            // 取消
            handelCancel() {
                history.back(-1);
            }
        }
    });
</script>
</html>
